//该文件用于创建vuex的store
import Vue from 'vue'
//引入vuex
import Vuex from 'vuex'
import {request} from "../api/axios";

Vue.use(Vuex)
//准备actions--用于响应组件中的动作。
const actions = {
  tonewsdetail(context, index) {
    context.commit('tonewsdetail', index)
  },
  toactivitydetail(context, index) {
    context.commit('toactivitydetail', index)
  },

  // 请求消息详情
  toinboxdetail({state, commit}, id) {
    let message = {}
    request({
      url: '/v1/messages/readmessage',
      method: 'post',
      data: {
        read_method: 0,
        user_name: state.userInfo.userName,
        id: id
      }
    }).then(res => {
      if (res.data.code === 200) {
        message = res.data.data
      }
      commit('toinboxdetail', message)
    })
  },

  // 请求活动详情
  toActivityDetail({commit}, id) {
    let activity = {}
    request({
      url: '/v1/activities/activitydetail',
      method: 'post',
      data: {
        id: id
      }
    }).then(res => {
      if (res.data.code === 200) {
        activity = res.data
      }
      commit('toActivityDetail', activity)
    })
  }
}
//准备mutations--用于操作数据。
const mutations = {
  // 将请求到的消息进行赋值
  toinboxdetail(state, message) {
    state.activeInbox = message
  },
  // 将请求到的活动进行赋值
  toActivityDetail(state, activity) {
    state.activeActivity = activity.data[0]
    state.newactivitycollecter = activity.collecter
    state.newactivityjoiner = activity.joiner
    state.newactivitycomments = activity.comments
  },
  tonewsdetail(state, index) {
    console.log(state.newnews[index])
  },
  toactivitydetail(state, index) {
    console.log(state.newactivity[index])
  },
  changelog(state) {
    state.islog = true
  },
  outlog(state) {
    state.logimg = require('@/assets/img/denglu.jpg')
    state.loguser = ''
    state.islog = false
  }
}
//准备state--用于存储数据。类似于data
const state = {
  // 用户上传静态资源的公共部分的url
  publicStaticPath: 'http://localhost:8000/media/',
  // 登录状态
  islog: false,
  userInfo: {
    isManagement: false,
    nickName: '',
    userName: '',
    avatar: '',
  },
  userdetail: {
    avatar: "userAvatar/2021-11-16_165658.175493__13991044970.jpg",
    create_time: "2021-11-18T16:13:52.148",
    email: "29664933395@qq.com",
    id: 21,
    nick_name: "",
    phone: "",
    qq_number: "",
    real_name: "",
    sex: "",
    user_edu_background: "",
    user_intro: "",
    user_name: "",
    user_nation: "",
    user_number: "",
    user_occupation: "",
    user_school: "",
    user_school_id: "",
    user_status: "",
  },

  // 当前处于活跃态的消息
  activeInbox: {},

  // 当前处于活跃的活动
  activeActivity: {},

  newactivityjoiner: [],
  newactivitycollecter: [],
  newactivitycomments: [],
  // 首页静态展示
  gonggaolan: [{
    biaoti: '志愿活动一',
    neirong: '今天有一个小组去曲江迎'
  },
    {
      biaoti: '志愿活动二',
      neirong: '今天有一个小组去曲江迎'
    },
    {
      biaoti: '志愿活动三',
      neirong: '今天有一个小组去曲江迎'
    },
  ],
  allactivity: [{
    // imgurl:'http://8.136.157.194:8000/media/',
    activity_address: "",
    activity_begin_time: "",
    activity_city: "",
    activity_cover: "",
    activity_create_time: "",
    activity_detail: "",
    activity_district: "",
    activity_end_time: "",
    activity_initiator_id: 0,
    activity_initiator_phone: "",
    activity_name: "",
    activity_participator_num: 0,
    activity_people_max_num: 0,
    activity_province: "",
    activity_status: "",
    activity_tag: "",
    id: 0,
  },],
  newnews: [{
    // imgurl:'http://8.136.157.194:8000/media/',
    id: 1,
    news_collect_num: 0,
    news_cover: "",
    news_create_time: "",
    news_detail: "",
    news_initiator_id: 21,
    news_initiator_phone: "",
    news_name: "",
    news_status: "",
    news_tag: "",
  },],
  newactivity: [{
    // imgurl:'http://8.136.157.194:8000/media/',
    activity_score: 100.00,
    activity_address: "",
    activity_begin_time: "",
    activity_city: "",
    activity_cover: "",
    activity_create_time: "",
    activity_detail: "",
    activity_district: "",
    activity_end_time: "",
    activity_initiator_id: 0,
    activity_initiator_phone: "",
    activity_name: "",
    activity_participator_num: 0,
    activity_people_max_num: 0,
    activity_province: "",
    activity_status: "",
    activity_tag: "",
    id: 0,
  },],
  OutstandingVolunteer: [{
    imageurl: require('../assets/img/照片1.jpg'),
    people: '双枪老太爷',
    volunteertime: '3000小时'
  },
    {
      imageurl: require('../assets/img/照片2.jpg'),
      people: '傲娇毁灭一切',
      volunteertime: '1598小时'
    },
    {
      imageurl: require('../assets/img/照片3.jpg'),
      people: '爱你不懂',
      volunteertime: '3094小时'
    },
    {
      imageurl: require('../assets/img/照片4.jpg'),
      people: '腾盛',
      volunteertime: '3522小时'
    },

  ],

  test: [],
}
//准备 getterss--用于将state中的数据进行加工。类似于computed。
const getters = {}
const store = new Vuex.Store({
  actions,
  mutations,
  state,
  getters
})
//导出store 
export default store
